using System;

namespace ProtoScratch.Common
{
	/// <summary>
	/// Scratch events is the primary interface used for both clients and servers to communicate.
	/// The ProtoScratch core uses this interface to communicate with the user application.
	/// </summary>
	public abstract class ScratchEvents
	{
		public Action<ScratchMessage> Send;
		public Action Close;
		private bool initialized; 
		
		/// <summary>
		/// ***FOR INTERNAL USE***
		/// This initializes a new connection.
		/// </summary>
		public void InitializeConnection(Action<ScratchMessage> Send, Action Close)
		{
			if (initialized)
				throw new ScratchException(ScratchException.eType.InvalidOperation, "Internal use only!");
			this.Send = Send;
			this.Close = Close;
			initialized = true;
			NewConnection();
		}
		
		public abstract void NewConnection();
		public abstract void MessageReceived(ScratchMessage Message);
		public abstract void ConnectionLost();
	}
}

